﻿Public Class OpenIT
    Implements IService

#Region "Constant"

    Const strName As String = "OpenIT"
    Const strURL As String = "sms.openit.de/put.php?"
    Const strHelp As String = ""
    Const strServiceURL As String = "http://www.openit.de"

#End Region

#Region "Variables"

    Private dtType As DataTable
    Private arrType As New ArrayList
    Private strDelay As String = Nothing
    Private bHTTPS As Boolean
    Private strPassword As String = Nothing
    Private strRecipient As String = Nothing
    Private strSender As String = Nothing
    Private strText As String = Nothing
    Private strUsername As String = Nothing
    Private strType As String = Nothing
    Private strParameter As String = Nothing
    Private dtParameter As DataTable

#End Region

#Region "Properties"

    Public ReadOnly Property Help() As String Implements IService.Help
        Get
            Return strHelp
        End Get
    End Property

    Public ReadOnly Property ServiceURL() As String Implements IService.ServiceURL
        Get
            Return strServiceURL
        End Get
    End Property

    Public Property Delay() As String Implements IService.Delay
        Get
            Return strDelay
        End Get
        Set(ByVal value As String)
            strDelay = value
        End Set
    End Property

    Public Property HTTPS() As Boolean Implements IService.HTTPS
        Get
            Return bHTTPS
        End Get
        Set(ByVal value As Boolean)
            bHTTPS = value
        End Set
    End Property

    Public ReadOnly Property Name() As String Implements IService.Name
        Get
            Return strName
        End Get
    End Property

    Public Property Password() As String Implements IService.Password
        Get
            Return strPassword
        End Get
        Set(ByVal value As String)
            strPassword = value
        End Set
    End Property

    Public Property Recipient() As String Implements IService.Recipient
        Get
            Return strRecipient
        End Get
        Set(ByVal value As String)
            strRecipient = value
        End Set
    End Property

    Public Property Sender() As String Implements IService.Sender
        Get
            Return strSender
        End Get
        Set(ByVal value As String)
            strSender = value
        End Set
    End Property

    Public Property Text() As String Implements IService.Text
        Get
            Return strText
        End Get
        Set(ByVal value As String)
            strText = value
        End Set
    End Property

    Public ReadOnly Property Types() As SMSType Implements IService.Types
        Get
            Dim ty As New SMSType
            ty.Add("1", "Standard", "160", False)
            Return ty
        End Get
    End Property

    Public ReadOnly Property URL() As String Implements IService.URL
        Get
            Return strURL
        End Get
    End Property

    Public Property Username() As String Implements IService.Username
        Get
            Return strUsername
        End Get
        Set(ByVal value As String)
            strUsername = value
        End Set
    End Property

    Public Property Type() As String Implements IService.Type
        Get
            Return strType
        End Get
        Set(ByVal value As String)
            strType = value
        End Set
    End Property

    Public Property Parameter() As String Implements IService.Parameter
        Get
            Return strParameter
        End Get
        Set(ByVal value As String)
            strParameter = value
        End Set
    End Property

    Public ReadOnly Property AdditionalParameter() As DataTable Implements IService.AdditionalParameter
        Get
            Dim AddParam As AdditionalParameter = New AdditionalParameter
            AddParam.Add("enc", True)
            AddParam.Add("maxparts", True)
            AddParam.Add("orig", True)
            AddParam.Add("personalised", True)
            AddParam.Add("project", True)
            AddParam.Add("registered_delivery", True)
            Return AddParam.Get()
        End Get
    End Property

#End Region

    Private Sub SetParameter(ByRef w As Web)
        If Not IsNothing(Parameter) Then
            dtParameter = Services.DeserializeObject(Parameter)
            Try
                If Not IsNothing(dtParameter) Then
                    For Each row As DataRow In dtParameter.Rows
                        w.AddParameter(row("Name"), row("Value"))
                    Next
                End If
            Catch ex As Exception
            End Try
        End If
    End Sub

    Public Function Info() As Object Implements IService.Info
        Dim W As New Web(Me.URL, Me.HTTPS)
        W.AddParameter("user", Username)
        W.AddParameter("pass", Password)
        W.AddParameter("orig", Sender)
        W.AddParameter("dest", Recipient)
        W.AddParameter("type", Type)
        W.AddParameter("data", Text, True)
        W.AddParameter("start_date", Delay)
        W.AddParameter("debug", 1)
        SetParameter(W)
        Return W.Request()
    End Function

    Public Function Send() As Object Implements IService.Send
        Dim W As New Web(Me.URL, Me.HTTPS)
        W.AddParameter("user", Username)
        W.AddParameter("pass", Password)
        W.AddParameter("orig", Sender)
        W.AddParameter("dest", Recipient)
        W.AddParameter("type", Type)
        W.AddParameter("data", Text, True)
        W.AddParameter("start_date", Delay)
        SetParameter(W)
        Return W.Request
    End Function

End Class
